package com.app.buss.mvp.presenter;

import android.content.Context;

import com.app.buss.bean.ChannalBean;
import com.app.buss.bean.ChannelParam;
import com.app.buss.bean.LlineBean;
import com.app.buss.mvp.view.IMainView;
import com.app.buss.utils.DeviceIdUtil;
import com.google.gson.Gson;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class MainPresenter extends BasePresenter<IMainView> {

    public MainPresenter(IMainView view) {
        attachView(view);
    }

    public void getConfig(Context context){
        mvpView.showLoading("loading...");
        ChannelParam param = new ChannelParam();
        param.timestamp = System.currentTimeMillis()+"";
        param.deviceId = DeviceIdUtil.getAndroidId(context);
        addSubscription(
                apiStores.getConfig(param.vestCode,param.version,param.deviceId,param.timestamp,param.channelCode),
                new ApiCallback<ChannalBean>() {

                    @Override
                    public void onSuccess(ChannalBean model) {
                        mvpView.getDataSuccess(model);
                    }

                    @Override
                    public void onFailure(String msg, int code) {
                        mvpView.getDataFail(msg);
                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }

    public void getKline(Context context,String code){
        mvpView.showLoading("loading...");
        addSubscription(
                apiStores.getKline(code),
                new ApiCallback<LlineBean>() {

                    @Override
                    public void onSuccess(LlineBean model) {
                        mvpView.getDataSuccess(model);
                    }

                    @Override
                    public void onFailure(String msg, int code) {
                        mvpView.getDataFail(msg);
                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }
}
